package com.wxp.demo08.list;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Spinner;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;

import com.wxp.demo08.R;
import com.wxp.demo08.list.adapter.PlanetBaseAdapter;
import com.wxp.demo08.list.model.PlanetModel;
import com.wxp.demo08.util.LogUtils;
import com.wxp.demo08.util.ToastUtil;

import java.util.List;

/**
 * 2.1 基本适配器BaseAdapter
 */
public class BaseAdapterActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener {

    /**
     * 行星列表数据
     */
    private List<PlanetModel> planetList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_base_adapter);
        this.setTitle("2.1 基本适配器BaseAdapter");


        // 获取默认的行星列表，即水星、金星、地球、火星、木星、土星
        planetList = PlanetModel.getDefaultList();
        // 构建一个行星列表的适配器
        PlanetBaseAdapter adapter = new PlanetBaseAdapter(this, planetList);

        Spinner sp_planet = findViewById(R.id.sp_planet);
        sp_planet.setAdapter(adapter);
        sp_planet.setSelection(0);
        sp_planet.setOnItemSelectedListener(this);

    }

    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
        ToastUtil.show(this, "您选择的是" + planetList.get(position).name);
    }

    @Override
    public void onNothingSelected(AdapterView<?> parent) {
        LogUtils.debug("没有任何选择-onNothingSelected");
    }
}